package work20241211.b;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author zdl
 * @date 2024/12/11
 */
public class Demo2 {
    public static void main(String[] args) {
        /**
         * 2题 键盘输入一段文字,将文字内容中文保留,大写变小写,小写变大写,数字剔除后输出
         *
         * 1) 键盘录入
         * 2) 将数据拆分成字符数组
         * 3) 准备一个StringBuilder的空字符串
         * 4) 遍历字符数组,判断大写(转小写),小写(转大写),是数字(不要),剩下的不动,原样拼接
         */
        //String text = "你好Java123";
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一段文字:");
        String text = sc.next();
        char[] charArray = text.toCharArray();
        System.out.println(Arrays.toString(charArray));
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < charArray.length; i++) {
            char c = charArray[i];
            if (Character.isLowerCase(c)){
                sb.append(Character.toUpperCase(c));
            } else if (Character.isUpperCase(c)) {
                sb.append(Character.toLowerCase(c));
            } else if (Character.isDigit(c)) {
                continue;
            }else {
                sb.append(c);
            }
        }
        System.out.println(sb);
    }
}
